.TH std::ostream_iterator::ostream_iterator 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::ostream_iterator::ostream_iterator \- std::ostream_iterator::ostream_iterator

.SH Synopsis
   ostream_iterator( ostream_type& stream, const CharT* delim ); \fB(1)\fP
   ostream_iterator( ostream_type& stream );                     \fB(2)\fP

   Constructs the iterator with stream as the associated stream, by storing the address
   of stream.

   1) Uses delim as the delimiter.
   2) Uses a null pointer as the delimiter.

.SH Parameters

   stream - the output stream to be accessed by this iterator
   delim  - the null-terminated character string to be inserted into the stream after
            each output

.SH Example


// Run this code

 #include <algorithm>
 #include <iostream>
 #include <iterator>
 #include <numeric>

 int main()
 {
     std::ostream_iterator<char> oo{std::cout};
     std::ostream_iterator<int> i1{std::cout, ", "};
     std::fill_n(i1, 5, -1);
     *oo++ = '\\n';

     std::ostream_iterator<double> i2{std::cout, "; "};
     *i2++ = 3.14;
     *i2++ = 2.71;
     *oo++ = '\\n';

     std::common_iterator<std::counted_iterator<std::ostream_iterator<float>>,
                          std::default_sentinel_t>
         first{std::counted_iterator{std::ostream_iterator<float>{std::cout," ~ "}, 5}},
         last{std::default_sentinel};
     std::iota(first, last, 2.2);
     *oo++ = '\\n';
 }

.SH Output:

 -1, -1, -1, -1, -1,
 3.14; 2.71;
 2.2 ~ 3.2 ~ 4.2 ~ 5.2 ~ 6.2 ~

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to          Behavior as published              Correct behavior
   LWG 1280 C++98      stream was stored directly               stores its address
                                                                instead
                       default constructor was provided as      removed along with
   P2325R3  C++20      C++20                                    the requirement
                       iterators must be default_initializable
